package com.stm.web.controller.basicData;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stm.basicData.domain.KfToolsEquipment;
import com.stm.basicData.domain.KfToolsType;
import com.stm.basicData.service.KfToolsEquipmentService;
import com.stm.common.annotation.Log;
import com.stm.common.core.controller.BaseController;
import com.stm.common.core.domain.AjaxResult;
import com.stm.common.core.page.TableDataInfo;
import com.stm.common.enums.BusinessType;
import com.stm.framework.util.ShiroUtils;

/**
 * 设备仪器Controller
 * 
 * @author wyc
 * @date 2019-04-08
 */
@Controller
@RequestMapping("/basicData/deviceEntry")
public class KfToolsEquipmentController extends BaseController
{
    private String prefix = "basicData/deviceEntry";
	
	@Autowired
	private KfToolsEquipmentService kfToolsEquipmentService;

	@RequiresPermissions("basicData:deviceEntry:list")
	@GetMapping()
	public String deviceEntry(ModelMap mmap)
	{
		
		mmap.put("user", ShiroUtils.getSysUser());
	    return prefix + "/deviceEntry";
	}
	
	/**
	 * 查询设备录入列表
	 */
	@RequiresPermissions("basicData:deviceEntry:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(KfToolsEquipment kfToolsEquipment)
	{
		startPage();
        List<KfToolsEquipment> list = kfToolsEquipmentService.selectAllPageList(kfToolsEquipment);
		return getDataTable(list);
	}
	
	/**
	 * 新增设备录入
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/deviceEntry_add";
	}
	
	/**
	 * 新增保存设备录入
	 */
	@RequiresPermissions("basicData:deviceEntry:add")
	@Log(title = "设备录入", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(@RequestBody KfToolsEquipment kfToolsEquipment)
	{
		kfToolsEquipment.setDprtcode(ShiroUtils.getSysUser().getDeptId());
		kfToolsEquipment.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(kfToolsEquipmentService.insertSelective(kfToolsEquipment));
	}

	/**
	 * 修改设备录入
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		KfToolsEquipment kfToolsEquipment = kfToolsEquipmentService.selectByPrimaryKey(id);
		mmap.put("kfToolsEquipment", kfToolsEquipment);
	    return prefix + "/deviceEntry_edit";
	}
	
	/**
	 * 修改保存设备录入
	 */
	@RequiresPermissions("basicData:deviceEntry:edit")
	@Log(title = "设备录入", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(KfToolsEquipment kfToolsEquipment)
	{
		kfToolsEquipment.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(kfToolsEquipmentService.updateByPrimaryKeySelective(kfToolsEquipment));
	}
	
	/**
	 * 删除设备录入
	 */
	@RequiresPermissions("basicData:deviceEntry:remove")
	@Log(title = "设备录入", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(kfToolsEquipmentService.deleteByIds(ids));
	}
	
    /**
     * 
     * @Description 初始化设备下拉
     * @CreateTime 2019年4月8日 上午11:22:58
     * @CreateBy 林龙
     * @param user
     * @return
     */
    @PostMapping("/initDvice")
    @ResponseBody
    public List<KfToolsEquipment> initDvice(KfToolsEquipment kfToolsEquipment)
    {
    	  return  kfToolsEquipmentService.selectAllPageList(kfToolsEquipment);
    }
	
}
